﻿using System;
using System.Diagnostics;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace RFC.AOP.UnitTest
{
    [TestClass]
    public class UnitTest1
    {
        [TestMethod]
        public void TestCreateInstance()
        {
            var version = "20170228";
            ITest test = ApectProxyBuilder.CreateInstance<ITest, Test>(version);
            Assert.IsNotNull(test);
            //Assert.AreEqual(version,test.Version);//属性需要再加入IL代码补充
            Assert.AreEqual(test.Get("123"),"123");
        }
    }

    public interface ITest
    {
        string Get(string message);

        //string Version { get; }
    }

    public class Test : ITest
    {
        public Test(string version)
        {
            //Version = version;
        }

        [ConsoleLog]
        public string Get(string message)
        {
            return message;
        }

        //public string Version { get; }
    }

    public class ConsoleLogAttribute : ApectBaseAttribute
    {
        public override void Before(ApectContext apectContext)
        {
            Trace.WriteLine("Before >" + apectContext.MethodName);
        }

        public override void After(ApectContext apectContext)
        {
            Trace.WriteLine("After >" + apectContext.MethodName);
        }
    }
}
